package com.fwlst.app

import android.util.Log
import com.fwlst.lib_base.BaseApp
import com.fwlst.lib_base.constant.AdConfig
import com.fwlst.lib_base.constant.AppConfig
import org.litepal.LitePal

class MyApp : BaseApp() {
    override fun onCreate() {
        super.onCreate()
        initAppConfig()
        initNormalSdk()
    }

    // 隐私政策同意后的sdk
    override fun initThirdSdk() {
        super.initThirdSdk()
        Log.d("initThirdSdk", "隐私政策同意后才能初始化的第三方SDK")
        /*=================litepal数据库=====================*/
        LitePal.initialize(this)

        //获取到SQLiteDatabase的实例，创建数据库表
        val db = LitePal.getDatabase()
    }

    private fun initAppConfig() {
        // 初始化是否是调试模式
        AppConfig.IS_DEBUG = BuildConfig.DEBUG

        // 初始化APP名称
        AppConfig.APP_NAME = BuildConfig.APP_NAME

        // 初始化备案号
        AppConfig.FILING_NO = BuildConfig.FILING_NO

        // 初始化应用ID
        AppConfig.APPLICATION_ID = BuildConfig.APPLICATION_ID

        // 初始化版本号
        AppConfig.VERSION_CODE = BuildConfig.VERSION_CODE

        // 初始化版本名称
        AppConfig.VERSION_NAME = BuildConfig.VERSION_NAME

        // 初始化公司名称
        AppConfig.COMPANY_NAME = BuildConfig.COMPANY_NAME

        // 初始化HTTP请求地址
        AppConfig.HTTP_URL = BuildConfig.HTTP_URL

        // 初始化隐私政策URL
        AppConfig.PRIVACY_URL = BuildConfig.PRIVACY_URL

        // 初始化用户协议URL
        AppConfig.USER_PROTOCOL_URL = BuildConfig.USER_PROTOCOL_URL

        // 初始化用户服务URL
        AppConfig.USER_SERVICE_URL = BuildConfig.USER_SERVICE_URL

        // 初始化用户会员URL
        AppConfig.USER_MEMBER_URL =
            "${BuildConfig.USER_SERVICE_URL}name=${AppConfig.APP_NAME}(${AppConfig.APPLICATION_ID})"

        // 初始化App的推广渠道
        AppConfig.APP_UMENG_CHANNEL = BuildConfig.APP_UMENG_CHANNEL

        // 初始化App的友盟 KEY
        AppConfig.APP_UMENG_KEY = BuildConfig.APP_UMENG_KEY

        // 初始化是否离线
        AppConfig.IS_OFFLINE = BuildConfig.IS_OFFLINE

        AdConfig.IS_SHOW_AD_ID = BuildConfig.IS_SHOW_AD_ID

        // 根据推广渠道初始化App的市场类型
        when (AppConfig.APP_UMENG_CHANNEL) {
            "HW" -> AppConfig.APP_MARKETS = 1
            "VIVO" -> AppConfig.APP_MARKETS = 2
            "XM" -> AppConfig.APP_MARKETS = 3
            "OPPO" -> AppConfig.APP_MARKETS = 4
            "YYB" -> AppConfig.APP_MARKETS = 5
            "BD" -> AppConfig.APP_MARKETS = 6
            "WDJ" -> AppConfig.APP_MARKETS = 7
            "RY" -> AppConfig.APP_MARKETS = 8
            "FF360" -> AppConfig.APP_MARKETS = 9
            "MZ" -> AppConfig.APP_MARKETS = 10
            "LX" -> AppConfig.APP_MARKETS = 11
            "ZYT" -> AppConfig.APP_MARKETS = 12
        }
    }
}